<?php
class FileUpload_Model{
    public $con;
    public function __construct(){
        $this->con =  mysqli_connect(DB_HOST,DB_USER,DB_PASSWORD,DB_NAME);
        if(mysqli_connect_error())
        {
            echo "Failed to connect to MySQL". mysqli_connect_error();exit();
        }
    }
    public function getLists(){
        $sql = "SELECT * FROM fileupload";
        $result = mysqli_query($this->con,$sql);
        return $result;
    }
    public function addCat($catname,$des){
        $sql = "INSERT INTO catfile(catname,des) VALUES('$catname','$des')";
        $result = mysqli_query($this ->con,$sql);
        $result = null;
    }
    public function getListCat(){
        $sql = "SELECT * FROM catfile";
        $result = mysqli_query($this->con,$sql);
        return $result;
    }
    public function delcat($id){
        $sql = "DELETE FROM catfile WHERE id = '$id'";
        $result = mysqli_query($this->con,$sql);
        $result = null;
    }
    public function viewcat($id){
        $sql = "SELECT * FROM catfile WHERE id = '$id'";
        $result = mysqli_query($this->con,$sql);
        return $result;
    }
    public function editcat($id,$catname,$des){
        $sql = "UPDATE catfile SET catname='$catname',des='$des' WHERE id = '$id'";
        $result = mysqli_query($this->con,$sql);
        $result = null;
    }
    public function upload($filename,$des,$link,$id_catfile){
        $sql = "INSERT INTO fileupload(filename,des,link,id_catfile) VALUES('$filename','$des','$link','$id_catfile')";
        $result = mysqli_query($this ->con,$sql);
        $result = null;
    }
}